package com.vworks.util;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

public final class QuarterUtils {
	
	public static List<String> querNewQuarterly(Date date){
		List<String> list=new ArrayList<String>();
		Calendar c=Calendar.getInstance();
		c.setTime(date);
		int year=c.get(Calendar.YEAR);
		int month=c.get(Calendar.MONTH)+1;
		int quarterly=quarterly(month);
		if(quarterly==0){
			quarterly=4;
			year=year-1;
		}else{
			quarterly=quarterly-1;
		}
		
		for(int i=quarterly;i>0;i--){
			list.add(year+"-"+(i*3)+"-"+day(i));
		}
		if(quarterly<4){
//			System.out.println("quarterly:"+quarterly);
			int j=4;
			for(int i=4-quarterly;i>0;i--){
				
				list.add(year-1+"-"+(j*3)+"-"+day(j));
				j--;
			}
		}
		return list;
	}

	public static int day(int quarterly){
		if(quarterly==2||quarterly==3){
			return 30;
		}
		return 31;
	}
	public static int quarterly(int month){
		if(month<4){
			return 1;
		}else if(month>3&&month<7){
			return 2;
		}else if(month>6&&month<10){
			return 3;
		}else if(month>9&&month<13){
			return 4;
		}
		return 1;
	}
	
	
	public static void main(String[] args) {
		List<String> list=querNewQuarterly(DateUtils.stringConvertDate("2012-10-10"));
		for(String s:list){
			System.out.println(s);
		}
	}
	
}
